#!/bin/bash
BkPath=/home/back
LogFile=/home/back/back.log
DBPath=/var/log
NewFile="$BkPath"/back$(date +%Y%m%d).tar.gz
OldFile="$BkPath"/back$(date +%Y%m%d --date='7 days ago').tar.gz
echo "---------------------------------------" >> $LogFile
echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile
echo "---------------------------------------" >> $LogFile

if [ -f $OldFile ];then
   rm -f $OldFile >> $LogFile 2>&1
   echo "the old file $OldFile 7 days ago delete success!" >> $LogFile
else
   echo "no old file $OldFile !" >> $LogFile
fi
tar cpzvf $NewFile $DBPath >> $LogFile 2>&1
echo "the file $DBPath backup successed!" >> $LogFile 2>&1  


